#ifndef _FLASH_H_
#define _FLASH_H_

struct flash_reg {
    volatile unsigned int ACR;
    volatile unsigned int KEYR;
    volatile unsigned int OPTKEYR;
    volatile unsigned int SR;
    volatile unsigned int CR;
    volatile unsigned int AR;
    volatile unsigned int RESERVED;
    volatile unsigned int OBR;
    volatile unsigned int WRPR;
    volatile unsigned int RESERVED1[8];
    volatile unsigned int KEYR2;
    volatile unsigned int RESERVED2;
    volatile unsigned int SR2;
    volatile unsigned int CR2;
    volatile unsigned int AR2;
};

// #define FLASH_KEY1               ((unsigned int)0x45670123)
// #define FLASH_KEY2               ((unsigned int)0xCDEF89AB)

void init_flash(void);
void flash_unlock(void);
void flash_clear_flag(void);
void flash_erase_page(unsigned int page);
void flash_write_halfword(unsigned int addr, unsigned short *data, unsigned int halfword_num);
void flash_lock(void);

extern volatile struct flash_reg *flash;

#endif
